'''
Created on 8 oct. 2012

@author: Nicolas
'''

import sqlite3

class db:
    
    def __init__(self):
        self.link = sqlite3.connect('data.db', check_same_thread = False)
        print 'Connecting to the database ..'
        self.connect()
        print 'Connected !'
        pass

    def connect(self):     
        self.link = sqlite3.connect('data.db')
        return self.link.cursor()
        pass
    
    def get_account(self, username):
        query = self.connect();
        query.execute('SELECT * FROM accounts WHERE username="'+ username + '"')
        _id, username, password, pseudo, rank = query.fetchone()  
        try:
            if(_id != None):
                return account(_id, username, password, pseudo, rank)
            else:
                return None
                pass
            pass
        except Exception:
            return None
            pass  
    pass

### Models ###

class account:
    
    def __init__(self, _id, username, password, pseudo, rank):
        self.id = _id
        self.username = username
        self.password = password
        self.pseudo = pseudo
        self.rank = rank
        pass
    
    pass